home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Lib / test / test_grammar.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2000-06-23  |  14.9 KB  |  681 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4. *
  5. print '1. Parser'
  6. print '1.1 Tokens'
  7. print '1.1.1 Backslashes'
  8. x = 1 + 1
  9. if x != 2:
  10.     raise TestFailed, 'backslash for line continuation'
  11.  
  12. x = 0
  13. if x != 0:
  14.     raise TestFailed, 'backslash ending comment'
  15.  
  16. print '1.1.2 Numeric literals'
  17. print '1.1.2.1 Plain integers'
  18. if 255 != 255:
  19.     raise TestFailed, 'hex int'
  20.  
  21. if 255 != 255:
  22.     raise TestFailed, 'octal int'
  23.  
  24. if 2147483647 != 2147483647:
  25.     raise TestFailed, 'large positive int'
  26.  
  27.  
  28. try:
  29.     maxint
  30. except ImportError:
  31.     maxint = 2147483647
  32.  
  33. if maxint == 2147483647:
  34.     if -2147483647 - 1 != -2147483648:
  35.         raise TestFailed, 'max negative int'
  36.     
  37.     if -1 != -1:
  38.         raise TestFailed, 'oct -1'
  39.     
  40.     if -1 != -1:
  41.         raise TestFailed, 'hex -1'
  42.     
  43.     for s in ('2147483648', '040000000000', '0x100000000'):
  44.         
  45.         try:
  46.             x = eval(s)
  47.         except OverflowError:
  48.             0
  49.             0
  50.             ('2147483648', '040000000000', '0x100000000')
  51.             continue
  52.         except:
  53.             0
  54.  
  55.         print 'No OverflowError on huge integer literal ' + `s`
  56.     
  57. elif eval('maxint == 9223372036854775807'):
  58.     if eval('-9223372036854775807-1 != 01000000000000000000000'):
  59.         raise TestFailed, 'max negative int'
  60.     
  61.     if eval('01777777777777777777777') != -1:
  62.         raise TestFailed, 'oct -1'
  63.     
  64.     if eval('0xffffffffffffffff') != -1:
  65.         raise TestFailed, 'hex -1'
  66.     
  67.     for s in ('9223372036854775808', '02000000000000000000000', '0x10000000000000000'):
  68.         
  69.         try:
  70.             x = eval(s)
  71.         except OverflowError:
  72.             0
  73.             0
  74.             ('9223372036854775808', '02000000000000000000000', '0x10000000000000000')
  75.             continue
  76.         except:
  77.             0
  78.  
  79.         raise TestFailed, 'No OverflowError on huge integer literal ' + `s`
  80.     
  81. else:
  82.     print 'Weird maxint value', maxint
  83. print '1.1.2.2 Long integers'
  84. x = 0x0L
  85. x = 0x0L
  86. x = 0xFFFFFFFFFFFFFFFFL
  87. x = 0xFFFFFFFFFFFFFFFFL
  88. x = 0x7FFFFFFFFFFFFL
  89. x = 0x7FFFFFFFFFFFFL
  90. x = 0x18EE90FF6C373E0EE4E3F0AD2L
  91. x = 0x18EE90FF6C373E0EE4E3F0AD2L
  92. print '1.1.2.3 Floating point'
  93. x = 3.14
  94. x = 314.0
  95. x = 0.314
  96. x = 0.314
  97. x = 3e+14
  98. x = 3e+14
  99. x = 3e-14
  100. x = 3e+14
  101. x = 3e+14
  102. x = 3e+13
  103. x = 31000.0
  104. print '1.1.3 String literals'
  105. x = ''
  106. y = ''
  107. if __debug__:
  108.     if not len(x) == 0 and x == y:
  109.         raise AssertionError
  110. x = "'"
  111. y = "'"
  112. if __debug__:
  113.     if not len(x) == 1 and x == y and ord(x) == 39:
  114.         raise AssertionError
  115. x = '"'
  116. y = '"'
  117. if __debug__:
  118.     if not len(x) == 1 and x == y and ord(x) == 34:
  119.         raise AssertionError
  120. x = 'doesn\'t "shrink" does it'
  121. y = 'doesn\'t "shrink" does it'
  122. if __debug__:
  123.     if not len(x) == 24 and x == y:
  124.         raise AssertionError
  125. x = 'does "shrink" doesn\'t it'
  126. y = 'does "shrink" doesn\'t it'
  127. if __debug__:
  128.     if not len(x) == 24 and x == y:
  129.         raise AssertionError
  130. x = '\nThe "quick"\nbrown fox\njumps over\nthe \'lazy\' dog.\n'
  131. y = '\nThe "quick"\nbrown fox\njumps over\nthe \'lazy\' dog.\n'
  132. if not __debug__ and x == y:
  133.     raise AssertionError
  134. y = '\nThe "quick"\nbrown fox\njumps over\nthe \'lazy\' dog.\n'
  135. if not __debug__ and x == y:
  136.     raise AssertionError
  137. y = '\nThe "quick"\nbrown fox\njumps over\nthe \'lazy\' dog.\n'
  138. if not __debug__ and x == y:
  139.     raise AssertionError
  140. y = '\nThe "quick"\nbrown fox\njumps over\nthe \'lazy\' dog.\n'
  141. if not __debug__ and x == y:
  142.     raise AssertionError
  143. print '1.2 Grammar'
  144. print 'single_input'
  145. print 'file_input'
  146. print 'expr_input'
  147. print 'eval_input'
  148. x = eval('1, 0 or 1')
  149. print 'funcdef'
  150.  
  151. def f1():
  152.     pass
  153.  
  154.  
  155. def f2(one_argument):
  156.     pass
  157.  
  158.  
  159. def f3(two, arguments):
  160.     pass
  161.  
  162.  
  163. def f4(two, .2):
  164.     (argument, list) = (compound,)
  165.  
  166.  
  167. def a1(one_arg):
  168.     pass
  169.  
  170.  
  171. def a2(two, args):
  172.     pass
  173.  
  174.  
  175. def v0(*rest):
  176.     pass
  177.  
  178.  
  179. def v1(a, *rest):
  180.     pass
  181.  
  182.  
  183. def v2(a, b, *rest):
  184.     pass
  185.  
  186.  
  187. def v3(a, .2, *rest):
  188.     (b, c) = .2
  189.  
  190.  
  191. def d01(a = 1):
  192.     pass
  193.  
  194. d01()
  195. d01(1)
  196.  
  197. def d11(a, b = 1):
  198.     pass
  199.  
  200. d11(1)
  201. d11(1, 2)
  202.  
  203. def d21(a, b, c = 1):
  204.     pass
  205.  
  206. d21(1, 2)
  207. d21(1, 2, 3)
  208.  
  209. def d02(a = 1, b = 2):
  210.     pass
  211.  
  212. d02()
  213. d02(1)
  214. d02(1, 2)
  215.  
  216. def d12(a, b = 1, c = 2):
  217.     pass
  218.  
  219. d12(1)
  220. d12(1, 2)
  221. d12(1, 2, 3)
  222.  
  223. def d22(a, b, c = 1, d = 2):
  224.     pass
  225.  
  226. d22(1, 2)
  227. d22(1, 2, 3)
  228. d22(1, 2, 3, 4)
  229.  
  230. def d01v(a = 1, *rest):
  231.     pass
  232.  
  233. d01v()
  234. d01v(1)
  235. d01v(1, 2)
  236.  
  237. def d11v(a, b = 1, *rest):
  238.     pass
  239.  
  240. d11v(1)
  241. d11v(1, 2)
  242. d11v(1, 2, 3)
  243.  
  244. def d21v(a, b, c = 1, *rest):
  245.     pass
  246.  
  247. d21v(1, 2)
  248. d21v(1, 2, 3)
  249. d21v(1, 2, 3, 4)
  250.  
  251. def d02v(a = 1, b = 2, *rest):
  252.     pass
  253.  
  254. d02v()
  255. d02v(1)
  256. d02v(1, 2)
  257. d02v(1, 2, 3)
  258.  
  259. def d12v(a, b = 1, c = 2, *rest):
  260.     pass
  261.  
  262. d12v(1)
  263. d12v(1, 2)
  264. d12v(1, 2, 3)
  265. d12v(1, 2, 3, 4)
  266.  
  267. def d22v(a, b, c = 1, d = 2, *rest):
  268.     pass
  269.  
  270. d22v(1, 2)
  271. d22v(1, 2, 3)
  272. d22v(1, 2, 3, 4)
  273. d22v(1, 2, 3, 4, 5)
  274. print 'simple_stmt'
  275. x = 1
  276. del x
  277. print 'expr_stmt'
  278. 1
  279. (1, 2, 3)
  280. x = 1
  281. x = (1, 2, 3)
  282. x = y = z = (1, 2, 3)
  283. (x, y, z) = (1, 2, 3)
  284. abc = (a, b, c) = (x, y, z) = xyz = (1, 2, (3, 4))
  285. print 'print_stmt'
  286. print 1, 2, 3
  287. print 1, 2, 3
  288. if not 0:
  289.     pass
  290. print 1,
  291. if not 0:
  292.     pass
  293. print 1,
  294. if not 0:
  295.     pass
  296. print 1
  297. print 'del_stmt'
  298. del abc
  299. del x
  300. del y
  301. del z
  302. del xyz
  303. print 'pass_stmt'
  304. print 'flow_stmt'
  305. print 'break_stmt'
  306. while 1:
  307.     break
  308. print 'continue_stmt'
  309. i = 1
  310. while i:
  311.     i = 0
  312.     continue
  313. print 'return_stmt'
  314.  
  315. def g1():
  316.     return None
  317.  
  318.  
  319. def g2():
  320.     return 1
  321.  
  322. g1()
  323. x = g2()
  324. print 'raise_stmt'
  325.  
  326. try:
  327.     raise RuntimeError, 'just testing'
  328. except RuntimeError:
  329.     pass
  330.  
  331.  
  332. try:
  333.     raise KeyboardInterrupt
  334. except KeyboardInterrupt:
  335.     pass
  336.  
  337. print 'import_stmt'
  338. import sys
  339. import time
  340. import sys
  341. time
  342. *
  343. argv
  344. print 'global_stmt'
  345. print 'exec_stmt'
  346. f()
  347. exec 'z = 1' in g
  348. if g != {
  349.     'z': 1 }:
  350.     raise TestFailed, "exec 'z = 1' in g"
  351.  
  352. g = { }
  353. l = { }
  354. exec 'global a; a = 1; b = 2' in g, l
  355. if g.has_key('__builtins__'):
  356.     del g['__builtins__']
  357.  
  358. if l.has_key('__builtins__'):
  359.     del l['__builtins__']
  360.  
  361. if (g, l) != ({
  362.     'a': 1 }, {
  363.     'b': 2 }):
  364.     raise TestFailed, 'exec ... in g, l'
  365.  
  366. print 'if_stmt'
  367. if 1:
  368.     pass
  369.  
  370. if 1:
  371.     pass
  372.  
  373. print 'while_stmt'
  374. while 0:
  375.     pass
  376. while 0:
  377.     pass
  378. print 'for_stmt'
  379. for i in (1, 2, 3):
  380.     pass
  381.  
  382. for i, j, k in ():
  383.     pass
  384.  
  385.  
  386. class Squares:
  387.     
  388.     def __init__(self, max):
  389.         self.max = max
  390.         self.sofar = []
  391.  
  392.     
  393.     def __len__(self):
  394.         return len(self.sofar)
  395.  
  396.     
  397.     def __getitem__(self, i):
  398.         if not None if i <= i else i < self.max:
  399.             raise IndexError
  400.         
  401.         n = len(self.sofar)
  402.         while n <= i:
  403.             self.sofar.append(n * n)
  404.             n = n + 1
  405.         return self.sofar[i]
  406.  
  407.  
  408. n = 0
  409. for x in Squares(10):
  410.     n = n + x
  411.  
  412. print 'try_stmt'
  413.  
  414. try:
  415.     1 / 0
  416. except ZeroDivisionError:
  417.     ()
  418.     ()
  419.     0
  420. except:
  421.     (1, 2, 3)
  422.  
  423.  
  424. try:
  425.     1 / 0
  426. except EOFError:
  427.     (1, 2, 3)
  428.     (1, 2, 3)
  429. except TypeError:
  430.     msg = None
  431. except RuntimeError:
  432.     msg = None
  433. except:
  434.     (1, 2, 3)
  435.  
  436.  
  437. try:
  438.     1 / 0
  439. except (EOFError, TypeError, ZeroDivisionError):
  440.     (1, 2, 3)
  441.     (1, 2, 3)
  442. except:
  443.     (1, 2, 3)
  444.  
  445.  
  446. try:
  447.     1 / 0
  448. except (EOFError, TypeError, ZeroDivisionError):
  449.     (1, 2, 3)
  450.     msg = (1, 2, 3)
  451. except:
  452.     (1, 2, 3)
  453.  
  454.  
  455. try:
  456.     pass
  457. finally:
  458.     pass
  459.  
  460. print 'suite'
  461. if 1:
  462.     pass
  463.  
  464. if 1:
  465.     pass
  466.  
  467. if 1:
  468.     pass
  469.  
  470. print 'test'
  471. if not 1:
  472.     pass
  473.  
  474. if 1 and 1:
  475.     pass
  476.  
  477. if 1 or 1:
  478.     pass
  479.  
  480. if not (not (not 1)):
  481.     pass
  482.  
  483. if not 1 and 1 and 1:
  484.     pass
  485.  
  486. if not 1 and 1:
  487.     if 1 and 1 and 1 and not 1 and 1:
  488.         pass
  489.     
  490. print 'comparison'
  491. if 1:
  492.     pass
  493.  
  494. x = 1 == 1
  495. if 1 == 1:
  496.     pass
  497.  
  498. if 1 != 1:
  499.     pass
  500.  
  501. if 1 != 1:
  502.     pass
  503.  
  504. if 1 < 1:
  505.     pass
  506.  
  507. if 1 > 1:
  508.     pass
  509.  
  510. if 1 <= 1:
  511.     pass
  512.  
  513. if 1 >= 1:
  514.     pass
  515.  
  516. if 1 is 1:
  517.     pass
  518.  
  519. if 1 is not 1:
  520.     pass
  521.  
  522. if 1 in ():
  523.     pass
  524.  
  525. if 1 not in ():
  526.     pass
  527.  
  528. if 1 < 1 and 1 > 1 and 1 == 1 and 1 >= 1 and 1 <= 1 and 1 != 1 and 1 != 1 and 1 in 1 and 1 not in 1 and 1 is 1:
  529.     pass
  530. elif 1 is not 1:
  531.     pass
  532.  
  533. print 'binary mask ops'
  534. x = 1 & 1
  535. x = 1 ^ 1
  536. x = 1 | 1
  537. print 'shift ops'
  538. x = 1 << 1
  539. x = 1 >> 1
  540. x = 1 << 1 >> 1
  541. print 'additive ops'
  542. x = 1
  543. x = 1 + 1
  544. x = 1 - 1 - 1
  545. x = ((1 - 1) + 1 - 1) + 1
  546. print 'multiplicative ops'
  547. x = 1 * 1
  548. x = 1 / 1
  549. x = 1 % 1
  550. x = (1 / 1) * 1 % 1
  551. print 'unary ops'
  552. x = +1
  553. x = -1
  554. x = ~1
  555. x = ~1 ^ 1 & 1 | 1 & 1 ^ -1
  556. x = -1 * 1 / 1 + 1 * 1 - ---1 * 1
  557. print 'selectors'
  558. f1()
  559. f2(1)
  560. f2(1)
  561. f3(1, 2)
  562. f3(1, 2)
  563. f4(1, (2, (3, 4)))
  564. v0()
  565. v0(1)
  566. v0(1)
  567. v0(1, 2)
  568. v0(1, 2, 3, 4, 5, 6, 7, 8, 9, 0)
  569. v1(1)
  570. v1(1)
  571. v1(1, 2)
  572. v1(1, 2, 3)
  573. v1(1, 2, 3, 4, 5, 6, 7, 8, 9, 0)
  574. v2(1, 2)
  575. v2(1, 2, 3)
  576. v2(1, 2, 3, 4)
  577. v2(1, 2, 3, 4, 5, 6, 7, 8, 9, 0)
  578. v3(1, (2, 3))
  579. v3(1, (2, 3), 4)
  580. v3(1, (2, 3), 4, 5, 6, 7, 8, 9, 0)
  581. import sys
  582. import time
  583. c = sys.path[0]
  584. x = time.time()
  585. x = sys.modules['time'].time()
  586. a = '01234'
  587. c = a[0]
  588. c = a[-1]
  589. s = a[0:5]
  590. s = a[:5]
  591. s = a[0:]
  592. s = a[:]
  593. s = a[-5:]
  594. s = a[:-1]
  595. s = a[-4:-3]
  596. print 'atoms'
  597. x = 1
  598. if not 1 and 2:
  599.     pass
  600. x = 3
  601. if not 1 and 2:
  602.     pass
  603. x = (3, 2, 3)
  604. x = []
  605. x = [
  606.     1]
  607. if not 1 and 2:
  608.     pass
  609. x = [
  610.     3]
  611. if not 1 and 2:
  612.     pass
  613. x = [
  614.     3,
  615.     2,
  616.     3]
  617. x = []
  618. x = { }
  619. x = {
  620.     'one': 1 }
  621. x = {
  622.     'one': 1 }
  623. if not 1:
  624.     pass
  625. if not 'one':
  626.     pass
  627. x = {
  628.     'two': 2 }
  629. x = {
  630.     'one': 1,
  631.     'two': 2 }
  632. x = {
  633.     'one': 1,
  634.     'two': 2 }
  635. x = {
  636.     'one': 1,
  637.     'two': 2,
  638.     'three': 3,
  639.     'four': 4,
  640.     'five': 5,
  641.     'six': 6 }
  642. x = `x`
  643. if not 1 and 2:
  644.     pass
  645. x = `3`
  646. x = x
  647. x = 'x'
  648. x = 123
  649. print 'classdef'
  650.  
  651. class B:
  652.     pass
  653.  
  654.  
  655. class C1(B):
  656.     pass
  657.  
  658.  
  659. class C2(B):
  660.     pass
  661.  
  662.  
  663. class D(C1, C2, B):
  664.     pass
  665.  
  666.  
  667. class C:
  668.     
  669.     def meth1(self):
  670.         pass
  671.  
  672.     
  673.     def meth2(self, arg):
  674.         pass
  675.  
  676.     
  677.     def meth3(self, a1, a2):
  678.         pass
  679.  
  680.  
  681.